package com.qs.controller;

import com.qs.ConStants;
import com.qs.pojo.SysUser;
import com.qs.pojo.vo.NavMenu;
import com.qss.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/index")
public class IndexController {
    @Reference
    private UserService userService;

    @GetMapping
    public String toIndex(HttpSession session, Model model){
        SysUser user = (SysUser)session.getAttribute(ConStants.CURR_USER);
        Integer roleId = user.getRoleId();
        // 根据角色ID查询角色所对应的资源信息
        // List
        // 放入到作用域中
        // 遍历  先遍历一级菜单 --->循环遍历当前一级菜单的子菜单
        // 一级菜单加一个List类型的属性

        List<NavMenu> child=userService.queryUserPermission(roleId);
        model.addAttribute("menu",child);
        return "index";
    }
}
